﻿var zombies = zombies || {};

zombies.aboutPubliser = function () {
    var self = this;
    //edit information
    self.ChannelName = ko.observable();
    self.About = ko.observable();
    self.PubId = ko.observable();

    self.doEdit = function () {
        var about = CKEDITOR.instances['about_ck'].getData();
        var dataToSave = {About: about};
        toastr.info(about);
        $.ajax({
            type: "PUT",
            url: "/api/Publisher/PutAbout",
            data: ko.toJSON(dataToSave),//Convert the Observable Data into JSON
            contentType: "application/json",
            dataType: 'json'
        }).done(function (data) {
            toastr.success('Chỉnh Sửa Thông Tinh Công ty Thành Công!');
            self.About(about);
            self.changeAction();
        }).fail(function (error) {
            toastr.error('Edit Advertise Failed !');
        });
    };

    self.changeAction = function () {
        $('#about_edit').fadeToggle('slow');
        $('#about_view').fadeToggle('slow')
    };
};

var loadChanel = function () {
    $.ajax({
        type: "GET",
        url: "/api/Publisher/GetCurrentChannel",
        contentType: "application/json",
        dataType: 'json'
    }).done(function (item) {
        aboutPubModel.PubId(item.PubId);
        aboutPubModel.ChannelName(item.ChannelName);
        aboutPubModel.About(item.About);
        CKEDITOR.instances['about_ck'].setData(item.About)
    }).fail(function () {
    });
};

var aboutPubModel;
$(document).ready(function () {
    aboutPubModel = new zombies.aboutPubliser();
    loadChanel();

    ko.applyBindings(aboutPubModel, document.getElementById("content_publisher"));
});